%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simulation of high-reflection coating.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;

n0 =1;          n1 =2.4;        n2 =1.5;
lss=.002;       Dz1=80e-9;      Dz2=500e-9;
lmb=[500:1:800]*1e-9;

M01 = 1/2/n1*[n1+n0 n1-n0 ; n1-n0 n1+n0];       M10 = 1/2/n0*[n0+n1 n0-n1 ; n0-n1 n0+n1];
M12 = 1/2/n2*[n2+n1 n2-n1 ; n2-n1 n2+n1];       M21 = 1/2/n1*[n1+n2 n1-n2 ; n1-n2 n1+n2];
Mlss= [exp(-lss) 0 ; 0 exp(lss)];

for kk=1:length(lmb)
    M1 = [exp(1i*2*pi*n1./lmb(kk)*Dz1) 0 ; 0 exp(-1i*2*pi*n1./lmb(kk)*Dz1)] * Mlss;
    M2 = [exp(1i*2*pi*n2./lmb(kk)*Dz2) 0 ; 0 exp(-1i*2*pi*n2./lmb(kk)*Dz2)] * Mlss;
    M  =  (M21 * M2 * M12 * M1)^10 * M01;
    Et(kk) = M(1,1)-M(1,2)*M(2,1)/M(2,2);
    Er(kk) = -M(2,1)/M(2,2);
end

R =   abs(Er).^2;
T =n1*abs(Et).^2;

figure(1);          clf;
subplot(221),plot(lmb*1e9,R)%,lmb*1e9,T,lmb*1e9,T+R)
set(gca,'FontSize',16,'xLim',[500 800],'yLim',[0 1])
xlabel('\fontsize{16}{\itlambda}   (nm)')
ylabel('\fontsize{16}{\itR}')